package com.knxhd.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.knxhd.service.Assistant;

import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;

/**
 * Author: tianluhua
 * Date: 2025-07-12 15:44:45
 * Description:
 */
@RestController
@RequestMapping(value = "/aiService")
public class AiServicesController {

  @Resource(name = "qwen")
  private ChatModel chatModel;

  @Resource(name = "ds")
  private ChatModel dsChatModel;

  @GetMapping(value = "/chat")
  public String chatString(@RequestParam(defaultValue = "你好") String input,
      @RequestParam(defaultValue = "qwen") String type) {

    Assistant assistant = null;
    if ("qwen".equals(type)) {
      assistant = AiServices.create(Assistant.class, chatModel);
    } else if ("ds".equals(type)) {
      assistant = AiServices.create(Assistant.class, dsChatModel);
      return dsChatModel.chat(input);
    }

    if (assistant == null) {
      return "请选择模型";

    }
    return assistant.chat(input);
  }
}
